<template>
  <div class="app-container">
    <el-card class="box-card">
      <div slot="header" class="clearfix">
        <span>基本信息</span>
      </div>
      <el-row :gutter="24" style="margin: 20px auto">
        <el-col :span="12">AppId：{{info.appid}}</el-col>
        <el-col :span="12">名称：{{info.name}}</el-col>
      </el-row>
      <el-row :gutter="24" style="margin: 20px auto">
        <el-col :span="12">联系人：{{info.concatName}}</el-col>
        <el-col :span="12">联系方式：{{info.concatMobile}}</el-col>
      </el-row>
      <el-row :gutter="24" style="margin: 20px auto">
        <el-col :span="12">秘钥：{{info.signKey}}</el-col>
        <el-col :span="12">回调地址：

         <span > {{info.notifyUrl}}</span>
          <el-button type="text" @click="mjwjreasoniptChg">修改</el-button>
        </el-col>
      </el-row>
      <el-row :gutter="24" style="margin: 20px auto">
        <el-col :span="12">免检价格：{{info.mjPrice}} /元</el-col>
        <el-col :span="12">代驾价格：{{info.djPrice}} /元</el-col>
      </el-row>
      <el-row :gutter="24" style="margin: 20px auto">
        <el-col :span="12">代驾业务：{{info.djEnable === 1 ? '启用' : '禁用'}} </el-col>
        <el-col :span="12">自驾业务：{{info.zjEnable === 1 ? '启用' : '禁用'}} </el-col>
      </el-row>
      <el-row :gutter="24" style="margin: 20px auto">
        <el-col :span="12">免检业务：{{info.mjEnable === 1 ? '启用' : '禁用'}} </el-col>
      </el-row>
    </el-card>

    <el-card class="box-card"  style="margin-top: 30px">
      <div slot="header" class="clearfix">
        <span>账户信息</span>
      </div>
      <el-row :gutter="24" style="margin: 20px auto">
        <el-col :span="12">账户余额：{{account.amount}}</el-col>
        <el-col :span="12">冻结金额：{{account.freeamount}}</el-col>
      </el-row>
    </el-card>

    <el-dialog :title="title" :visible.sync="edit" width="500px">
      <el-form ref="form" :model="form"  label-width="80px">
        <el-form-item label="回调地址" prop="gmtTime">
          <el-input
            v-model="form.notifyUrl"
            placeholder="请输入回调地址"
            clearable
            size="small"
          />
        </el-form-item>
      </el-form>

      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitAudit">确 定</el-button>
        <el-button @click="cancelmjwj">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
  import {listAccount, getAccount, chargeAccount, updateAccount} from "@/api/third/account";
  import Bill from "../bill/index"

  export default {
    name: "Account",
    components: {Bill},
    data() {
      return {
        // 遮罩层
        loading: true,
        // 选中数组
        ids: [],
        // 非单个禁用
        edit: false,
        // 非多个禁用
        multiple: true,
        // 总条数
        total: 0,
        // 弹出层标题
        title: "",
        // 是否显示弹出层
        open: false,
        billopen: false,
        // 查询参数
        queryParams: {
        },
        // 表单参数
        form: {
          notifyUrl:''
        },
        chargeform: {},
        // 表单校验
        rules: {},
        info:{},
        account:{},
        accountId: undefined,

      };
    },
    created() {
      this.getList();
    },
    methods: {
      /** 查询第三方合伙人账户列表 */
      getList() {
        this.loading = true;
        listAccount(this.queryParams).then(response => {
          this.account = response.data.account;
          this.info = response.data.info;
          this.form.notifyUrl = this.info.notifyUrl;
          this.loading = false;
        });
      },
      // 取消按钮
      cancel() {
        this.open = false;
        this.reset();
      },
      // 表单重置
      resetchargeform() {
        this.chargeform = {
          id: undefined,
          appid: undefined,
          name: undefined,
          amount: 0,
        };
        this.resetForm("form");
      },
      /** 搜索按钮操作 */
      handleQuery() {
        this.queryParams.pageNum = 1;
        this.getList();
      },
      /** 重置按钮操作 */
      resetQuery() {
        this.resetForm("queryForm");
        this.handleQuery();
      },
      // 多选框选中数据
      handleSelectionChange(selection) {
        this.ids = selection.map(item => item.id)
        this.single = selection.length != 1
        this.multiple = !selection.length
      },
      /** 新增按钮操作 */
      handleAdd() {
        this.reset();
        this.open = true;
        this.title = "添加第三方合伙人账户";
      },
      /** 修改按钮操作 */
      handleUpdate(row) {
        this.reset();
        this.resetchargeform();
        const id = row.id || this.ids
        getAccount(id).then(response => {
          this.form = response.data;
          this.chargeform.id = this.form.id,
            this.chargeform.appid = this.form.appid,
            this.chargeform.name = this.form.name,
            this.open = true;
          this.title = "账户充值";
        });
      },

      /** 修改按钮操作 */
      handleBill(row) {
        this.accountId = row.id;
        this.billopen = true;
        this.title = "账单";
      },
      /** 提交按钮 */
      submitForm: function () {
        this.$refs["form"].validate(valid => {
          if (valid) {
            if (this.chargeform.id != undefined) {
              chargeAccount(this.chargeform).then(response => {
                if (response.code === 200) {
                  this.msgSuccess("充值成功");
                  this.open = false;
                  this.getList();
                } else {
                  this.msgError(response.msg);
                }
              });
            }
          }
        });
      },
      submitAudit: function () {
        updateAccount(this.form).then(response => {
          if (response.code === 200) {
            this.msgSuccess("修改成功");
            this.edit = false;
            this.getList();
          } else {
            this.msgError(response.msg);
          }
        });
      },
      mjwjreasoniptChg(){
        this.edit = true;
      },
      // 取消按钮
      cancelmjwj() {
        this.edit = false;
      },
    }
  };
</script>
